function init_upload() {
	$("#loading")
	.ajaxStart(function(){
		//$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	
	var options = {
		beforeSubmit:  showRequest,
		success:       showResponse,
		url:       '/module1/upload',  // your upload script
		dataType:  'json'
	};
	$('#Form1').change(function() {
		//alert("123");
		document.getElementById('message').innerHTML = '';
		$(this).ajaxSubmit(options);
		//return false;
	});
	
	//click Add button -> select picture
	/**/
	$("ul.add-image-button").click(function(){
		//alert("click");
		$("input#fileToUpload").click();
	});
}

function showRequest(formData, jqForm, options) {
	var fileToUploadValue = $('#fileToUpload').fieldValue();
	//alert("showR");
	if (!fileToUploadValue[0]) {
		document.getElementById('message').innerHTML = 'Please select a file.';
		return false;
	} 

	return true;
} 

function showResponse(data, statusText)  {
	//if (!data) return;
	if (statusText == 'success') {
		if (data.img != '') {
			//document.getElementById('result').innerHTML = '<img src="/uploads/images/thumb/'+data.img+'" />';
			//document.getElementById('message').innerHTML = data.error;
			addNewImage(data.img);
		} else {
			document.getElementById('message').innerHTML = data.error;
		}
	} else {
		document.getElementById('message').innerHTML = 'Unknown error!';
	}
}